package com.ruoyi.security.elevator.util;

import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.TreeMap;

public class Signed {
	/**
	 * 生成sign
	 *
	 * @param map
	 * @param
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String getSignString(TreeMap<String, Object> map)  {

		try {
			String appSecret = (String)map.get("appSecret");

			StringBuilder sb = new StringBuilder();

			sb.append(appSecret);
			for (Map.Entry<String, Object> entry : map.entrySet()) {
				if ((!entry.getKey().equalsIgnoreCase("sign")) && (!entry.getKey().equalsIgnoreCase("v")) && (!entry.getKey().equalsIgnoreCase("appSecret"))){
					sb.append(entry.getKey().toLowerCase()+entry.getValue());
				}
			}
			sb.append(appSecret);

			String paramStrs = sb.toString();
			paramStrs = java.net.URLEncoder.encode(paramStrs, "UTF-8")
					.toUpperCase();

			String mySign = Md5Util.generate32md5(paramStrs).toUpperCase();

			map.remove("appSecret");

			return mySign;
		} catch (Exception ex) {
			return "";
		}
	}
}
